#!/usr/bin/env python

import webapp2
from google.appengine.ext.webapp import util
import wxparser
import logging

class MainHandler(webapp2.RequestHandler):
	def get(self):
		
#		logging.info(self.request)
		
		s = '<html><table>'
		s += '<tr><td>' + wxparser.getCurrentConditions('KJFK')
		s += '<tr><td>' + wxparser.getCurrentConditions('KLGA')
		s += '<tr><td>' + wxparser.getCurrentConditions('KNYC')
		s += '<tr><td>' + wxparser.getCurrentConditions('44065')
		s += '<tr><td>FCAST: <a href="/zip/10974">10974</a> <a href="/zip/10001">10001</a>'
		s += '</table>'
		self.response.out.write(s)

class WxHandler(webapp2.RequestHandler):
	def get(self):
#		logging.info(self.request)
		shortReport = self.request.headers['User-Agent'].lower().find('blackberry') >= 0
		self.response.out.write(wxparser.parse(self.request.path, shortReport))

class MtaHandler(webapp2.RequestHandler):
	def get(self):
#		logging.info(self.request)
		self.response.out.write(mta.load_alerts())

def main():
	application = webapp2.WSGIApplication(
		[('/', MainHandler),
		('/zip/.*', WxHandler)],
		debug=True)
	util.run_wsgi_app(application)

if __name__ == '__main__':
	main()
